package com;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class TestHTTP {

	public static void main(String[] args) {

		StringBuffer responseStringBuffer = null;
		URLConnection connection = null;
		URL reqUrl = null;
		OutputStreamWriter reqOut = null;
		InputStream in = null;
		BufferedReader br = null;
		String param = null;
		try{
			responseStringBuffer = new StringBuffer();
			reqUrl = new URL("http://localhost:8080/MyWeb/Server?test");
			connection = reqUrl.openConnection();
			connection.setDoOutput(true);
			reqOut = new OutputStreamWriter(connection.getOutputStream());
			reqOut.write("me");
			reqOut.flush();
			
			int charCount = -1;
			in = connection.getInputStream();
			br = new BufferedReader(new InputStreamReader(in, "GBK"));
			while((charCount = br.read()) != -1){
				responseStringBuffer.append((char)charCount);
			}
			System.out.println(responseStringBuffer.toString());
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
